<template>
  <div>
    <el-col :span="24" class="propertyborder-content">
      <el-button size="small" style="width: 100%" type="primary" @click="openwhereconfig">填充规则设置</el-button>
    </el-col>
    <zhlDialog title="填充规则设置" ref="refassignFiledConfig" width="960px" class="my-dialog">
      <assignFiledConfig :selectfiledList="selectfiledList" :assignFiledList="assignFiledList" @saveinfo="saveAssignFiled" @close="$refs.refassignFiledConfig.visible=false" :controlinfo="contdata"></assignFiledConfig>
    </zhlDialog>
  </div>
</template>
<script>
import { getApiConfigByCallMethodCode } from '@/api/packageInterface.js'
import assignFiledConfig from '@/components/formdesign/assignFiledConfig.vue'
export default {
  props: ['contdata'],
  data () {
    return { assignFiledList: [], selectfiledList: [] }
  },
  components: { assignFiledConfig },
  methods: {
    saveAssignFiled (assignFiledList) {
      this.assignFiledList = assignFiledList
      this.contdata.options.assignFiledList = assignFiledList
      this.$refs.refassignFiledConfig.visible = false
    },
    openwhereconfig () {
      if (this.contdata.options.sourceApi !== '') {
        getApiConfigByCallMethodCode(this.contdata.options.sourceApi).then(res => {
          if (res.code === 0) {
            this.selectfiledList = JSON.parse(res.data.headList)
            this.$refs.refassignFiledConfig.visible = true
          }
        })
      } else {
        this.$message.error('请先选择请求地址')
      }
    }
  },
  created () {
    this.assignFiledList = this.contdata.options.assignFiledList
  },
  watch: {
    contdata (val) {
      this.assignFiledList = val.options.assignFiledList
    }
  }
}
</script>
<style scoped>
.propertyborder-title {
  height: 42px;
  line-height: 42px;
  padding-left: 3px;
  border: 1px solid #ccc;
  border-top: none;
  border-right: none;
}

.propertyborder-content {
  border: 1px solid #ccc;
  border-top: none;
  border-right: none;
  padding-right: 3px;
  padding-left: 3px;
  padding-top: 4px;
  padding-bottom: 4px;
  height: 42px;
}
</style>
